//
//  LSContactListViewController.m
//  LaSaCivilAffairsDepartment
//
//  Created by 聂志康 on 2019/2/12.
//  Copyright © 2019 wpkj. All rights reserved.
//

#import "LSContactListViewController.h"
#import "LSContactListTableViewCell.h"

@interface LSContactListViewController () <UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableView;
@end

static NSString *LSContactListTableViewCellID = @"LSContactListTableViewCellID";

@implementation LSContactListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self.view addSubview:self.tableView];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.displayListArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    LSContactListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:LSContactListTableViewCellID forIndexPath:indexPath];
    cell.dataDict = self.displayListArray[indexPath.row];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return LSContactListTableViewCellHeight;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:true];
    NSDictionary *dataDict = self.displayListArray[indexPath.row];
    if ([[ValidateUtils validateNull:dataDict[@"phone"]] isEqualToString:@""]) {
        [MBProgressHUD showTipMessageInWindow:@"电话号码错误"];
        return;
    }
    NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"tel:%@",dataDict[@"phone"]];
    UIWebView * callWebview = [[UIWebView alloc] init];
    [callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];
    [self.view addSubview:callWebview];
}

- (UITableView *)tableView {
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight-SafeAreaTopHeight)];
        _tableView.separatorInset = UIEdgeInsetsZero;
        _tableView.backgroundColor = UIColor.whiteColor;
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.tableFooterView = [UIView new];
        _tableView.backgroundColor = hexColor(EEEEEE);
        [_tableView registerClass:LSContactListTableViewCell.class forCellReuseIdentifier:LSContactListTableViewCellID];
    }
    return _tableView;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
